package champPackage;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ChampionshipRegistrationServlet
 */
@WebServlet("/ChampionshipRegistrationServlet")
public class ChampionshipRegistrationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChampionshipRegistrationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name=request.getParameter("name");
		String start=request.getParameter("start");
		String end=request.getParameter("end");
		DBManager db=DBManager.getInstance();
		//dasamatebelia  axali user klasis sheqmna da mere DBmanager-is magivrad championsgip class-s gamoviyenebt
		int id=0;
		try {
			id=db.getNewChampionshipId();
			db.addNewChampionship(id, 13);
			db.addChampionshipName(id, name);
			db.addchampionshipStart(id, start);
			db.addchampionshipend(id, end);
			System.out.println(id+", "+name+", "+start+", "+end+".");
			RequestDispatcher dispatcher=request.getRequestDispatcher("championshipRegistered.jsp");
			dispatcher.forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
